﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AIFSContentManagementSystem.Criteria
{
    public sealed class NumericExpression : Expression
    {
        public override ExpressionDataType DataType
        {
            get
            {
                return ExpressionDataType.NUMERIC;
            }
        }

        protected override bool CanCompare(Expression other)
        {
            if (!(other is NumericExpression))
                return false;

            Decimal dec;

            bool tryParse = Decimal.TryParse(this.ExpressionElement.RightOperand, out dec);
            if (!tryParse)
                return false;

            tryParse = Decimal.TryParse(other.ExpressionElement.RightOperand, out dec);
            if (!tryParse)
                return false;

            return true;
        }

        protected override int CompareTo(Expression other)
        {
            Decimal thisNumber;
            Decimal otherNumber;

            Decimal.TryParse(this.ExpressionElement.RightOperand, out thisNumber);
            Decimal.TryParse(other.ExpressionElement.RightOperand, out otherNumber);

            return thisNumber.CompareTo(otherNumber);
        }
    }
}
